from server.db.repository.message_repository import delete_messages_by_user_id
from fastapi import Body, Request
from configs.logging_config import configure_logging
from loguru import logger
from server.utils import BaseResponse
from pydantic import BaseModel


class UserInfo(BaseModel):
    uid: str = Body(..., description="用户ID")


# 删除用户历史对话记录
async def delete_user_history_message(request: UserInfo):
    uid = request.uid
    try:
        # 删除用户的历史对话记录
        delete_count = delete_messages_by_user_id(uid)
        return BaseResponse(code=200, msg=f"删除用户的历史对话记录成功，共删除 {delete_count} 条记录")
    except Exception as e:
        logger.error(f"删除用户的历史对话记录失败: {e}")
        return BaseResponse(code=500, msg="删除用户的历史对话记录失败")
